<?php

namespace app\service;

use Couchbase\PreparedStatementException;
use \think\facade\Filesystem;
class UploadService
{
    public function upload($file)
    {
        try {
            // 上传到本地服务器 public/uploads/目录
            $savename = Filesystem::disk('public')->putFile( '/uploads', $file);
            $domain = request()->domain();
            //获取当前域名 https:// 判断http的话转https
            if (strpos($domain, 'http://') !== false) {
                $domain = str_replace('http://', 'https://', $domain);
            }
            return $domain."/storage/".$savename;

        }catch (\Exception $e){
            throw new PreparedStatementException($e->getMessage());
        }

    }
}
